package com.yx.front.controller;


import com.yx.front.annotation.AnonymousAccess;
import com.yx.front.config.global.CommonResult;
import com.yx.front.manager.ChapterMessageManager;
import com.yx.front.model.param.ChapterMessageParam;
import com.yx.front.model.vo.BookChapterVo;
import com.yx.front.model.vo.ChapterMessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 章节信息表 前端控制器
 * </p>
 *
 * @author YangXiong
 * @since 2023-03-29
 */
@Slf4j
@RestController
@RequestMapping("/chapter-message")
@Api(tags = "章节信息前端控制器")
public class ChapterMessageController {

    @Resource
    private ChapterMessageManager chapterMessageManager;

    @PostMapping("/page")
    @AnonymousAccess
    @ApiOperation("根据书本id分页查询章节")
    public CommonResult<List<BookChapterVo>> getPage(@RequestBody ChapterMessageParam param) {
        log.info("ChapterMessageController info getPage ChapterMessageParam={}", param);
        return chapterMessageManager.getPage(param);
    }

    @PostMapping("/list")
    @AnonymousAccess
    @ApiOperation("根据书本id分页查询章节")
    public CommonResult<List<Long>> getList(@RequestBody ChapterMessageParam param) {
        log.info("ChapterMessageController info getPage ChapterMessageParam={}", param);
        return chapterMessageManager.getList(param);
    }

    @PostMapping("/detail")
    @PreAuthorize("@ex.hasAuthority('query')")
    @ApiOperation("根据id查询章节")
    public CommonResult<ChapterMessageVo> getDetailById(@RequestBody ChapterMessageParam param) {
        log.info("ChapterMessageController info getDetailById ChapterMessageParam={}", param);
        return chapterMessageManager.getDetailById(param);
    }

}

